#include"QuickSort.h"
Swap(int* p1, int* p2)
{
	int tmp = *p1;
	*p1 = *p2;
	*p2 = tmp;
}
void ArrPrint(int* arr, int n)
{
	int i = 0;
	for (i = 0; i < n; i++)
	{
		printf("%d", arr[i]);
	}
	printf("\n");
}
int SortKey(int* arr,int left,int right)
{
	int keyi = left;
	while (left < right)
	{
		while (right > left && arr[right] >= arr[keyi])
		{
			right--;
		}
		while (right > left && arr[left] <= arr[keyi])
		{
			left++;
		}
		Swap(&arr[left], &arr[right]);
	}
	Swap(&arr[keyi], &arr[left]);
	return left;
}
void QuickSort(int* arr, int begin, int end)
{
	if (begin >= end)
	{
		return;
	}
	int key = SortKey(arr, begin, end);
	
	QuickSort(arr, begin, key - 1);
	QuickSort(arr, key + 1, end);

}